/**
 * This file is a part of qloudgen-rul. 
 * You can redistribute qloudgen-rul and/or modify it under the terms of the Lesser GNU General Public License version 3. 
 * qloudgen-rul is distributed WITHOUT ANY WARRANTY. 
 *
 * See the Lesser GNU General Public License for more details at http://www.gnu.org/licenses/. 
 **/
package org.qloudgen.rul.drools.rule;

import org.qloudgen.sec.util.StringUtil;

/**
 * <p>Title: Drools Implementation</p>
 * <p>Description: Wrappered jboss drools module release id implementation.</p>
 * <p>Copyright: qloudgen/rul 2014</p>
 * @author <a href="mailto:hyq.dd.sun@gmail.com">glue.3M</a>
 */
public final class DroolsReleaseId {
	/**
	 *
	 */
	public final static String VERSION_LATEST = "LATEST";
	/**
	 *
	 */
	public final static String VERSION_RELEASE = "RELEASE";
	/**
	 *
	 */
	private String groupId = null;
	/**
	 *
	 */
	private String artifactId = null;
	/**
	 *
	 */
	private String version = null;
	
	/**
	 * Default constructor.
	 */
	public DroolsReleaseId() {
		this( null , null );
	}
	
	/**
	 * Custom constructor.
	 *
	 * @param groupId
	 * @param artifactId
	 */
	public DroolsReleaseId(String groupId , String artifactId) {
		this( groupId , artifactId , VERSION_LATEST );
	}
	
	/**
	 * Custom constructor.
	 *
	 * @param groupId
	 * @param artifactId
	 * @param version
	 */
	public DroolsReleaseId(String groupId , String artifactId , String version) {
		this.groupId = groupId;
		this.artifactId = artifactId;
		this.version = version;
	}
	
	/**
	 * Sets current group id.
	 *
	 * @param groupId
	 */
	public void setGroupId(final String groupId) {
		this.groupId = groupId;
	}
	
	/**
	 * Returns current group id.
	 *
	 * @return String
	 */
	public String getGroupId() {
		return groupId;
	}
	
	/**
	 * Sets current artifact id.
	 *
	 * @param artifactId
	 */
	public void setArtifactId(final String artifactId) {
		this.artifactId = artifactId;
	}
	
	/**
	 * Returns current artifact id.
	 *
	 * @return String
	 */
	public String getArtifactId() {
		return artifactId;
	}
	
	/**
	 * Sets current version.
	 *
	 * @param version
	 */
	public void setVersion(final String version) {
		this.version = version;
	}
	
	/**
	 * Returns current version.
	 *
	 * @return String
	 */
	public String getVersion() {
		return version;
	}
	
	/**
	 * Returns the equals representation.
	 *
	 * @return boolean
	 */
	@Override
	public boolean equals(Object obj) {
		if ( obj == null || getClass() != obj.getClass() ) {
			return false;
		}
		DroolsReleaseId target = ( DroolsReleaseId )obj;
		if ( ! StringUtil.compare( groupId , target.getGroupId() ) ) {
			return false;
		}
		if ( ! StringUtil.compare( artifactId , target.getArtifactId() ) ) {
			return false;
		}
		if ( ! StringUtil.compare( version , target.getVersion() ) ) {
			return false;
		}
		//
		return true;
	}
	
	/**
	 * Returns the hash code representation.
	 *
	 * @return boolean
	 */
	@Override
	public int hashCode() {
		int result = ( groupId != null ? groupId.hashCode() : 0 );
		result = 31 * result + ( artifactId != null ? artifactId.hashCode() : 0 );
		result = 31 * result + ( version != null ? version.hashCode() : 0 );
		return result;
	}
	
	/**
	 * Returns the String representation.
	 *
	 * @return String
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append( "[" );
		builder.append( super.toString() );
		builder.append( "-->" );
		builder.append( "groupId=" ).append( groupId ).append( "," );
		builder.append( "artifactId=" ).append( artifactId ).append( "," );
		builder.append( "version=" ).append( version );
		builder.append( "]" );
		//
		return builder.toString();
	}
}